//
//  SearchHeaderView.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/5/22.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "SearchHeaderView.h"
#import "IGUtil.h"
@interface SearchHeaderView()

@property (nonatomic, strong)UILabel * label;
@property (nonatomic, strong)UIButton * deleteBtn;

@property (nonatomic, strong)UIView * lineView;
@end
@implementation SearchHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    
    self =[super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        
        UILabel * label = [[UILabel alloc] init];
        label.textColor = kTitleColor;
        label.font = Font(14);
        label.text = @"搜索记录";
        
        [self.contentView addSubview:label];
        self.label = label;
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView.mas_leading).offset(20);
            make.top.equalTo(self.contentView.mas_top);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.deleteBtn setImage:[UIImage imageNamed:@"删除_浅"] forState:UIControlStateNormal];
        [self.deleteBtn addTarget:self action:@selector(delete) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.deleteBtn];
        [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.contentView.mas_trailing).offset(-10);
            make.top.equalTo(self.contentView.mas_top);
            make.bottom.equalTo(self.contentView.mas_bottom);
            make.width.mas_equalTo(50);
            
        }];
        
        self.lineView = [[UIView alloc] init];
        self.lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [self.contentView addSubview:self.lineView];
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.contentView.mas_trailing).offset(-16);
            make.leading.equalTo(self.contentView.mas_leading).offset(16);
            make.bottom.equalTo(self.contentView.mas_bottom);
            make.height.mas_equalTo(1.0);
        }];
    }
    
    return self;
}

-(void)delete {
    
    if (_delegate ) {
        
        [_delegate deleteAllHistroy];
    }
}

- (void)setTitle:(NSString *)title {
    
    _title = title;
    self.label.text = title;
}

- (void)setHideDeleteBtn:(BOOL)hideDeleteBtn {
    
    self.deleteBtn.hidden = hideDeleteBtn;
    self.lineView.hidden = hideDeleteBtn;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
